const { createApp } = Vue;

createApp({
    data() {
        return {
            currentSlide: 0,
            slides: [
                {
                    subtitle: '专业心理咨询平台',
                    title: '让每个人都能获得<br>专业的心理支持',
                    description: '一对一专业咨询，帮助您解决心理困扰，找回内心的平静',
                    image: 'images/slide1.jpg'
                },
                {
                    subtitle: '专业团队保障',
                    title: '资深心理咨询师<br>全程陪伴守护',
                    description: '严格筛选的专业团队，为您提供优质的心理健康服务',
                    image: 'images/slide2.jpg'
                },
                {
                    subtitle: '便捷的服务体验',
                    title: '线上线下结合<br>灵活预约咨询',
                    description: '提供多样化的咨询方式，让心理健康服务触手可及',
                    image: 'images/slide3.jpg'
                }
            ]
        };
    },
    methods: {
        goToPage(page) {
            // 检查登录状态
            const token = localStorage.getItem('token');
            const userType = localStorage.getItem('userType');

            switch (page) {
                case 'index':
                    window.location.href = 'index.html';
                    break;
                case 'consultation':
                    window.location.href = 'consultation.html';
                    break;
                case 'therapist':
                    window.location.href = 'therapist.html';
                    break;
                case 'about':
                    window.location.href = 'about.html';
                    break;
                case 'user-center':
                    if (!token) {
                        alert('请先登录');
                        window.location.href = 'login.html';
                        return;
                    }
                    if (userType === 'therapist') {
                        window.location.href = 'therapist/index.html';
                    } else {
                        window.location.href = 'user-center.html';
                    }
                    break;
                case 'login':
                    if (token) {
                        if (userType === 'therapist') {
                            window.location.href = 'therapist/index.html';
                        } else {
                            window.location.href = 'user-center.html';
                        }
                    } else {
                        window.location.href = 'login.html';
                    }
                    break;
            }
        },
        startAutoSlide() {
            setInterval(() => {
                this.nextSlide();
            }, 5000);
        },
        prevSlide() {
            this.currentSlide = (this.currentSlide - 1 + this.slides.length) % this.slides.length;
        },
        nextSlide() {
            this.currentSlide = (this.currentSlide + 1) % this.slides.length;
        },
        setSlide(index) {
            this.currentSlide = index;
        }
    },
    mounted() {
        this.startAutoSlide();
    }
}).mount('#app'); 